var num = [2, 7, 11, 15], target = 4



for (var i = 0; i < nums.length; i++) {
    var res = target - nums[i]
    var index = nums.indexOf(res, i + 1)

    if (index !== -1) {
        return [i, index]
    }
}